<!DOCTYPE html>
<html>

<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>H+ 后台主题UI框架 - 空白页</title>
    <meta name="keywords" content="">
    <meta name="description" content="">

    <link rel="shortcut icon" href="favicon.ico">
     <link href="__STATIC__/layout/css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="__STATIC__/layout/css/font-awesome.css?v=4.4.0" rel="stylesheet">
     <!-- jqgrid-->
    <link href="__STATIC__/layout/css/animate.css" rel="stylesheet">
    <link href="__STATIC__/layout/css/style.css?v=4.1.0" rel="stylesheet">
    <link href="__STATIC__/layout/css/plugins/sweetalert/sweetalert.css" rel="stylesheet">
    <link href="__STATIC__/layout/css/gyq.css" rel="stylesheet">
    <link rel="stylesheet" href="__STATIC__/layout/css/demo.css" type="text/css">
     <link rel="stylesheet" href="__STATIC__/layout/css/channel.css" type="text/css">
    <style>
		   .radio-inline input[type=radio] {
            margin-top: 4px
        }
        .note-editable{height: 200px}
        .closeit,.closefei{float: right;
    font-size: 21px;
    font-weight: 700;
    line-height: 1;
    color: #000;
    text-shadow: 0 1px 0 #fff;
    filter: alpha(opacity=20);
    opacity: .2;
	cursor: pointer;
}
    </style>
</head>

<body style="color:#333;padding:3px;" class="x_sorll">
    <!-- 标题 -->
    <div class="page-heade">
      <h1 class="title_color">AP费用申请明细</h1>
    </div>
    <!-- 标题 -->
    <div class="row-margin-top">
    <form action=""  class="form-inline" id="f1">
    	<input type="hidden" name="aid" id="aid" value="{$aid}"/>
       <table class="table-bordered table t_table">
       	{switch name="$area" }
       		{case value="1"}
       			<input type="hidden" name="fenqu" id="tag1" tag="分区"/>
       		{/case}
       		{case value="2"}
       			<input type="hidden" name="sheng" id="tag1" tag="省份"/>
       		{/case}
       		{case value="3"}
       			<input type="hidden" name="shi" id="tag1" tag="城市"/>
       		{/case}
       		{case value="4"}
       			<input type="hidden" name="jxs" id="tag1" tag="经销商"/>
       		{/case}
       		{case value="5"}
       			<input type="hidden" name="system" id="tag1" tag="系统"/>
       		{/case}
       		{case value="6"}
       			<input type="hidden" name="net" id="tag1" tag="网点"/>
       		{/case}
       	{/switch}
       	{switch name="$area" }
       		{case value="1"}
          	<tr>
                <td style="min-width: 180px;width: 180px" class="text-right">
                    <label for="">分区<span class="colorRed">*</span>：</label>
                </td>
                <td colspan="3">
                    <div class="col-xs-4">
                        <div class="input-group" id="" >
                            <input type="text"   placeholder="请输入关键字或空格查询" class="form-control inputremindPeple" id="fenqu"  value="{:isset($supply)?$supply.jxs:''}">
                            <div class="input-group-btn">
                                <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
                                    <span class="caret"></span>
                                </button>
                                <ul class="dropdown-menu dropdown-menu-right" role="menu">
                                </ul>
                            </div>
                        </div>
                    </div>
                    <div class="col-xs-2">
                        <button class="btn btn-primary btn-sm" type="button" id="select_fenqu">选择</button>
                        <button class="btn btn-primary btn-sm clear_net"  type="button" >清空</button>
                    </div>
                </td>
            </tr>
            <tr>
                <td style="min-width: 180px;width: 180px" class="text-right"><label for="">您选定的分区是：</label></td>
                <td class="text-left" colspan="3">
                    <div class="duoxuan" id="selected_fenqu">
                    </div>
                </td>
            </tr>
			{/case}
			{case value="2"}
				<tr>
	                <td style="min-width: 180px;width: 180px" class="text-right">
	                    <label for="">省份<span class="colorRed">*</span>：</label>
	                </td>
	                <td colspan="3">
	                    <div class="col-xs-4">
	                        <div class="input-group" id="" >
	                            <input type="text"   placeholder="请输入关键字或空格查询" class="form-control inputremindPeple" id="sheng"  value="{:isset($supply)?$supply.jxs:''}">
	                            <div class="input-group-btn">
	                                <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
	                                    <span class="caret"></span>
	                                </button>
	                                <ul class="dropdown-menu dropdown-menu-right" role="menu">
	                                </ul>
	                            </div>
	                        </div>
	                    </div>
	                    <div class="col-xs-2">
	                        <button class="btn btn-primary btn-sm" type="button" id="select_sheng">选择</button>
	                        <button class="btn btn-primary btn-sm clear_net"  type="button" >清空</button>
	                    </div>
	                </td>
	            </tr>
	            <tr>
	                <td style="min-width: 180px;width: 180px" class="text-right"><label for="">您选定的省份是：</label></td>
	                <td class="text-left" colspan="3">
	                    <div class="duoxuan" id="selected_sheng">
	                    </div>
	                </td>
	            </tr>
			{/case}
			{case value="3"}
				<tr>
	                <td style="min-width: 180px;width: 180px" class="text-right">
	                    <label for="">城市<span class="colorRed">*</span>：</label>
	                </td>
	                <td colspan="3">
	                    <div class="col-xs-4">
	                        <div class="input-group" id="" >
	                            <input type="text"   placeholder="请输入关键字或空格查询" class="form-control inputremindPeple" id="shi"  value="{:isset($supply)?$supply.jxs:''}">
	                            <div class="input-group-btn">
	                                <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
	                                    <span class="caret"></span>
	                                </button>
	                                <ul class="dropdown-menu dropdown-menu-right" role="menu">
	                                </ul>
	                            </div>
	                        </div>
	                    </div>
	                    <div class="col-xs-2">
	                        <button class="btn btn-primary btn-sm" type="button" id="select_shi">选择</button>
	                        <button class="btn btn-primary btn-sm clear_net"  type="button" >清空</button>
	                    </div>
	                </td>
	            </tr>
	            <tr>
	                <td style="min-width: 180px;width: 180px" class="text-right"><label for="">您选定的城市是：</label></td>
	                <td class="text-left" colspan="3">
	                    <div class="duoxuan" id="selected_shi">
	                    </div>
	                </td>
	            </tr>
			{/case}
			{case value="4"}
				<tr>
	                <td style="min-width: 180px;width: 180px" class="text-right">
	                    <label for="">经销商<span class="colorRed">*</span>：</label>
	                </td>
	                <td colspan="3">
	                    <div class="col-xs-4">
	                        <div class="input-group" id="" >
	                            <input type="text"   placeholder="请输入关键字或空格查询" class="form-control inputremindPeple" id="jxs"  value="{:isset($supply)?$supply.jxs:''}">
	                            <div class="input-group-btn">
	                                <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
	                                    <span class="caret"></span>
	                                </button>
	                                <ul class="dropdown-menu dropdown-menu-right" role="menu">
	                                </ul>
	                            </div>
	                        </div>
	                    </div>
	                    <div class="col-xs-2">
	                        <button class="btn btn-primary btn-sm" type="button" id="select_jxs">选择</button>
	                        <button class="btn btn-primary btn-sm clear_net"  type="button" >清空</button>
	                    </div>
	                </td>
	            </tr>
	            <tr>
	                <td style="min-width: 180px;width: 180px" class="text-right"><label for="">您选定的经销商是：</label></td>
	                <td class="text-left" colspan="3">
	                    <div class="duoxuan" id="selected_jxs">
	                    </div>
	                </td>
	            </tr>
			{/case}
			{case value="5"}
				<tr>
	                <td style="min-width: 180px;width: 180px" class="text-right">
	                    <label for="">系统<span class="colorRed">*</span>：</label>
	                </td>
	                <td colspan="3">
	                    <div class="col-xs-4">
	                        <div class="input-group" id="" >
	                            <input type="text"   placeholder="请输入关键字或空格查询" class="form-control inputremindPeple" id="xt"  value="{:isset($supply)?$supply.jxs:''}">
	                            <div class="input-group-btn">
	                                <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
	                                    <span class="caret"></span>
	                                </button>
	                                <ul class="dropdown-menu dropdown-menu-right" role="menu">
	                                </ul>
	                            </div>
	                        </div>
	                    </div>
	                    <div class="col-xs-2">
	                        <button class="btn btn-primary btn-sm" type="button" id="select_xt">选择</button>
	                        <button class="btn btn-primary btn-sm clear_net"  type="button" >清空</button>
	                    </div>
	                </td>
	            </tr>
	            <tr>
	                <td style="min-width: 180px;width: 180px" class="text-right"><label for="">您选定的系统是：</label></td>
	                <td class="text-left" colspan="3">
	                    <div class="duoxuan" id="selected_xt">
	                    </div>
	                </td>
	            </tr>
			{/case}
			{case value="6"}
				<tr>
	                <td style="min-width: 180px;width: 180px" class="text-right">
	                    <label for="">网点<span class="colorRed">*</span>：</label>
	                </td>
	                <td colspan="3">
	                    <div class="col-xs-4">
	                        <div class="input-group" id="" >
	                            <input type="text"   placeholder="请输入关键字或空格查询" class="form-control inputremindPeple" id="wangdian"  value="{:isset($supply)?$supply.jxs:''}">
	                            <div class="input-group-btn">
	                                <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
	                                    <span class="caret"></span>
	                                </button>
	                                <ul class="dropdown-menu dropdown-menu-right" role="menu">
	                                </ul>
	                            </div>
	                        </div>
	                    </div>
	                    <div class="col-xs-2">
	                        <button class="btn btn-primary btn-sm" type="button" id="select_wangdian">选择</button>
	                        <button class="btn btn-primary btn-sm clear_net"  type="button" >清空</button>
	                    </div>
	                </td>
	            </tr>
	            <tr>
	                <td style="min-width: 180px;width: 180px" class="text-right"><label for="">您选定的网点是：</label></td>
	                <td class="text-left" colspan="3">
	                    <div class="duoxuan" id="selected_wangdian">
	                    </div>
	                </td>
	            </tr>
			{/case}
           {/switch}
            {switch name="$pro" }
           	{case value="1"}
				<input type="hidden" name="brand" id="tag2" tag="品牌"/>
           	{/case}
           	{case value="2"}
				<input type="hidden" name="category" id="tag2" tag="品类"/>
           	{/case}
           	{case value="3"}
				<input type="hidden" name="series" id="tag2" tag="系列"/>
           	{/case}
           	{/switch}
           {switch name="$pro" }
           	{case value="1"}
           <tr>
                <td style="min-width: 180px;width: 180px" class="text-right">
                    <label for="">品牌<span class="colorRed">*</span>：</label>
                </td>
                <td colspan="3">
                    <div class="col-xs-4">
                        <div class="input-group" id="" >
                            <input type="text"   placeholder="请输入关键字或空格查询" class="form-control inputremindPeple" id="brand" value="{:isset($supply)?$supply.jxs:''}">
                            <div class="input-group-btn">
                                <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
                                    <span class="caret"></span>
                                </button>
                                <ul class="dropdown-menu dropdown-menu-right" role="menu">
                                </ul>
                            </div>
                        </div>
                    </div>
                    <div class="col-xs-2">
                        <button class="btn btn-primary btn-sm" type="button" id="select_brand">选择</button>
                        <button class="btn btn-primary btn-sm clear_net"  type="button" >清空</button>
                    </div>
                </td>
            </tr>
            <tr>
                <td style="min-width: 180px;width: 180px" class="text-right"><label for="">您选定的品牌是：</label></td>
                <td class="text-left" colspan="3">
                    <div class="duoxuan" id="selected_brand">
                    </div>
                </td>
            </tr>
           {/case}
           {case value="2"}
				  <tr>
                <td style="min-width: 180px;width: 180px" class="text-right">
                    <label for="">品类<span class="colorRed">*</span>：</label></td>
                <td colspan="3">
                    <div class="col-xs-4">
                        <div class="input-group" id="" >
                            <input type="text"   placeholder="请输入关键字或空格查询" class="form-control inputremindPeple" id="category" value="{:isset($supply)?$supply.jxs:''}">
                            <div class="input-group-btn">
                                <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
                                    <span class="caret"></span>
                                </button>
                                <ul class="dropdown-menu dropdown-menu-right" role="menu">
                                </ul>
                            </div>
                        </div>
                    </div>
                    <div class="col-xs-2">
                        <button class="btn btn-primary btn-sm" id="select_category">选择</button>
                        <button class="btn btn-primary btn-sm clear_net">清空</button>
                    </div>
                </td>
            </tr>
            <tr>
                <td style="min-width: 180px;width: 180px" class="text-right"><label for="">您选定的品类是：</label></td>
                <td class="text-left" colspan="3">
                    <div class="duoxuan" id="selected_category"></div>
                </td>
            </tr>
           {/case}
           {case value='3'}
			 <tr>
                <td style="min-width: 180px;width: 180px" class="text-right">
                    <label for="">系列<span class="colorRed">*</span>：</label></td>
                <td colspan="3">
                    <div class="col-xs-4">
                        <div class="input-group" id="" >
                            <input type="text"   placeholder="请输入关键字或空格查询" class="form-control inputremindPeple" id="series"  value="{:isset($supply)?$supply.jxs:''}">
                            <div class="input-group-btn">
                                <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
                                    <span class="caret"></span>
                                </button>
                                <ul class="dropdown-menu dropdown-menu-right" role="menu">
                                </ul>
                            </div>
                        </div>
                    </div>
                    <div class="col-xs-2">
                        <button class="btn btn-primary btn-sm" id="select_series">选择</button>
                        <button class="btn btn-primary btn-sm clear_net" >清空</button>
                    </div>
                </td>
            </tr>
            <tr>
                <td style="min-width: 180px;width: 180px" class="text-right"><label for="">您选定的系列是：</label></td>
                <td class="text-left" colspan="3">
                    <div class="duoxuan" id="selected_series"></div>
                </td>
            </tr>
           {/case}
           {/switch}
            <tr>
                <td style="min-width: 180px;width: 180px" class="text-right">
                    <label for="">三级费用科目<span class="colorRed">*</span>：</label></td>
                <td colspan="3">
                    <div class="col-xs-4">
                        <div class="input-group" id="" >
                            <input type="text"   placeholder="请输入关键字或空格查询" class="form-control inputremindPeple" id="feiyong3" value="{:isset($supply)?$supply.jxs:''}">
                            <div class="input-group-btn">
                                <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
                                    <span class="caret"></span>
                                </button>
                                <ul class="dropdown-menu dropdown-menu-right" role="menu">
                                </ul>
                            </div>
                        </div>
                    </div>
                    <div class="col-xs-2">
                        <button class="btn btn-primary btn-sm" id="select_feiyong3">选择</button>
                        <button class="btn btn-primary btn-sm clear_feiyong" >清空</button>
                    </div>
                </td>
            </tr>
            <tr>
                <td style="min-width: 180px;width: 180px" class="text-right"><label for="">您选定的三级费用科目是：</label></td>
                <td class="text-left" colspan="3">
                    <div class="duoxuan" id="selected_feiyong3"></div>
                </td>
            </tr>
             <tr>
            <td style="min-width: 200px;width: 200px" class="text-right"><label for="" >活动执行时间<span class="colorRed">*</span>：</label></td>
            <td>
            <div class="form-group">
            <input type="text" id="start" class="form-control layer-date " style="min-width:100px;width:120px;display: inline-block;" name="start">
           </div>
            <div class="form-group">
                至
            </div>
           <div class="form-group">
            <input type="text" class="form-control layer-date" style="min-width:100px;width:120px;display: inline-block;" id="end" name="end">
           </div>
            </td>
            <td style="min-width: 200px;width: 200px" class="text-right"><label for="" >预计核销时间<span class="colorRed">*</span>：</label></td>
            <td><input type="text" class="form-control layer-date" name="yjverifyTime" id="yjverifyTime"></td>
           </tr>
           <tr>
               <td style="min-width: 200px;width: 200px" class="text-right"><label for="" >预计总销量(元)<span class="colorRed">*</span>：</label></td>
               <td><input type="text" class="form-control" name="yjallshop" id="yjallshop"></td>
                 <td style="min-width: 200px;width: 200px" class="text-right"><label for="" >总基准销量(元)<span class="colorRed">*</span>：</label></td>
               <td><input type="text" class="form-control" name="allbaseshop" id="allbaseshop"></td>
           </tr>
        </table>
   
      <table class="table-bordered table t_table" style="margin:1px">
      <thead>
        <tr class="info">
            <th class="text-center">费用类型</th>
            <th class="text-center">供应商<span class="colorRed">*</span></th>
            <th class="text-center">未税总额(元)<span class="colorRed">*</span></th>
            <th class="text-center">是否增值税<br>(可抵扣)<span class="colorRed">*</span></th>
             <th class="text-center">税率<span class="colorRed">*</span></th>
            <th class="text-center">含税总额(元)</th>
            <th class="text-center">实际投入<br>总额(元)</th>
            <th class="text-center">支付方式<span class="colorRed">*</span></th>
        </tr>
       </thead>
       <tbody id="tb">
        
        </tbody>
        <tfoot>
        <tr>
            <td class="text-right" row="2">项目描述<span class="colorRed">*</span></td>
            <td colspan="7">
                <textarea name="description" id="description" rows="2" class="form-control" style="width: 50%"></textarea><span style="vertical-align: bottom;">(200)</span>
            </td>
        </tr>
         <tr>
            <td class="text-right" row="2" >备注</td>
            <td colspan="7">
                <textarea name="remark" id="" rows="2" class="form-control" style="width: 50%" ></textarea><span style="vertical-align: bottom;">(200)</span>
            </td>
        </tr>
        </tfoot>
    </table>
       <div class="row sub_btn white-bg" style="width:100%;text-align:center;padding: 20px 0">
        <input type="button" class="btn btn-success" value="保存并再添加一条" id="saveAdd">
        <input type="button" class="btn btn-success" value="保存并并返回"  id="saveBack">
        <input type="button" class="btn btn-warning" value="返回" id="fanhui">
    </div>
</form>
    </div>
    <!-- 全局js -->
    <script src="__STATIC__/layout/js/jquery.min.js?v=2.1.4"></script>
    <script src="__STATIC__/layout/js/bootstrap.min.js?v=3.3.6"></script>
    <!-- <script src="js/plugins/metisMenu/jquery.metisMenu.js"></script> -->
    <script src="__STATIC__/layout/js/plugins/slimscroll/jquery.slimscroll.min.js"></script>
    <script src="__STATIC__/layout/js/plugins/layer/laydate/laydate.js"></script>
    <script src="__STATIC__/layout/js/plugins/sweetalert/sweetalert.min.js"></script>
    <script src="__STATIC__/layout/js/plugins/slimscroll/jquery.slimscroll.min.js"></script>
<script src="__STATIC__/layout/js/plugins/layer/laydate/laydate.js"></script>
<script src="__STATIC__/layout/js/plugins/layer/layer.min.js"></script>

<script src="__STATIC__/layout/js/plugins/suggest/bootstrap-suggest.min.js"></script>
    <!--统计代码，可删除-->
    <script>
         //返回
    $('#fanhui').click(function () {
       parent.window.location="{:url('addform')}?aid="+$("#aid").val();
    })
     var channel={$channel};
     var area={$area};
     var pro={$pro};
    $("#yjallshop,#allbaseshop").blur(function(){
    	if(isNaN(parseFloat($(this).val()))){
    		$(this).val("0.00");
    	}else{
    		$(this).val(parseFloat($(this).val()).toFixed(2));
    	}
    })
    //验证
    function yanzheng(){
    	var message=[];
    	var flag=0;
    	if($("#yjverifyTime").val()==""){
         	message["msg"]="预计核销时间必须填写";message["state"]=2;
         	return message;
         }
        if($("#start").val()==""){
         	message["msg"]="活动开始时间必须填写";message["state"]=2;
         	return message;
         }
        if($("#end").val()==""){
         	message["msg"]="活动结束时间必须填写";message["state"]=2;
         	return message;
         }
         if($("#yjallshop").val()==""){
         	message["msg"]="预计总销量不能为空";message["state"]=2;
         	return message;
         }
          if($("#yjallshop").val()=="0.00"){
         	message["msg"]="预计总销量不能为0";message["state"]=2;
         	return message;
         }
          if($("#allbaseshop").val()=="0.00"){
         	message["msg"]="总基准销量不能为0";message["state"]=2;
         	return message;
         }
         if($("#description").val()==""){
         	message["msg"]="项目描述不能为空";message["state"]=2;
         	return message;
         }
         flag=0;
         $(".infoContent").each(function(){
         	flag++;
         })
         if(flag==0){
         	message["msg"]="至少添加一条费用明细";message["state"]=2;
         	return message;
         }
         flag=0;
          $(".gys").each(function(){
         	if($(this).val()==""){
         			flag=1;
         		}
         })
           if(flag==1){
         	message["msg"]="供应商必须选择";message["state"]=2;
         	return message;
         }

         flag=0;
          $(".weishui").each(function(){
         	if($(this).val()==""||$(this).val()=="0.00"){
         			flag=1;
         		}
         })
           if(flag==1){
         	message["msg"]="未税金额必须填写且不能为0";message["state"]=2;
         	return message;
         }
          flag=0;
          $(".zfid").each(function(){
         	if($(this).val()=="0"){
         			flag=1;
         		}
         })
           if(flag==1){
         	message["msg"]="支付方式必须选择";message["state"]=2;
         	return message;
         }
         var tmp=[];
         $(".duoxuan").eq(0).children(".ren").each(function(){
         	tmp.push($(this).attr("data-id"));
         })
        $("#tag1").val(tmp.join(','));
        if($("#tag1").val()==""){
        	message["msg"]="至少选择一个"+$("#tag1").attr("tag");message["state"]=2;
         	return message;
        }
        var tmp2=[];
         $(".duoxuan").eq(1).children(".ren").each(function(){
         	tmp2.push($(this).attr("data-id"));
         })
        $("#tag2").val(tmp2.join(','));
        if($("#tag2").val()==""){
        	message["msg"]="至少选择一个"+$("#tag2").attr("tag");message["state"]=2;
         	return message;
        }
    	message["msg"]="";message["state"]=1;
        return message;
    }
    //保存新增
    $("#saveAdd").click(function(){
    	var res=yanzheng();
    	if(res["state"]==1){
    		if($("input[name='aid']").val()==0){
    			//无申请
    			$.ajax({
               			cache: true,
               			type: "POST",
                		url:"{:url('Apapply/addapply')}",
                		data:parent.$('#zhuapply').serialize(),// 你的formid
                		async: false,
		                error: function(request) {
		                    alert("Connection error");
		                },
		                success:function(data){
		                	var rea=JSON.parse(data);
		                	if(rea["aid"]!=0){
		                		$("#aid").val(rea["aid"]);
		                		$.ajax({
		               			cache: true,
		               			type: "POST",
		                		url:"{:url('addapplydetail')}",
		                		data:$('#f1').serialize(),// 你的formid
		                		async: false,
				                error: function(requests) {
				                    alert("Connection error");
				                },
				                success:function(datas){
				                	var res1=JSON.parse(datas);
				                	if(res1["state"]==1){
				                		swal({
										title: "完成",
										text: "操作已成功",
										type: "success"
										},function(){
											location.href="{:url('addData')}?aid="+$("#aid").val()+"&channel="+channel+"&pro="+pro+"&area="+area;
										});
				                	}else{
				                		swal({
										title: "错误",
										text:  res1["msg"],
										type: "warning"
										});
				                	}
				                }
				               })
		                	}else{
		                		swal({
									title: "错误",
									text:  rea["msg"],
									type: "warning"
									});
    
		                	}
		                	

		                }
		           })
	    	}else{
	    		//有申请
	    				$.ajax({
		               			cache: true,
		               			type: "POST",
		                		url:"{:url('addapplydetail')}",
		                		data:$('#f1').serialize(),// 你的formid
		                		async: false,
				                error: function(requests) {
				                    alert("Connection error");
				                },
				                success:function(datas){
				                	var res1=JSON.parse(datas);
				                	if(res1["state"]==1){
				                		swal({
										title: "完成",
										text: "操作已成功",
										type: "success"
										},function(){
											location.href="{:url('addData')}?aid="+$("#aid").val()+"&channel="+channel+"&pro="+pro+"&area="+area;
										});
				                	}else{
				                		swal({
										title: "错误",
										text:  res1["msg"],
										type: "warning"
										});
				                	}
				                }
				               })
	    	}
    	}else{
    			swal({
					title: "错误",
					text:  res["msg"],
					type: "warning"
					});
    	}
    	
    })
    //保存返回
    $("#saveBack").click(function(){
    	var res=yanzheng();
    	if(res["state"]==1){
    		if($("input[name='aid']").val()==0){
    			//无申请
    			$.ajax({
               			cache: true,
               			type: "POST",
                		url:"{:url('Apapply/addapply')}",
                		data:parent.$('#zhuapply').serialize(),// 你的formid
                		async: false,
		                error: function(request) {
		                    alert("Connection error");
		                },
		                success:function(data){
		                	var rea=JSON.parse(data);
		                	if(rea["aid"]!=0){
		                		$("#aid").val(rea["aid"]);
		                		$.ajax({
		               			cache: true,
		               			type: "POST",
		                		url:"{:url('addapplydetail')}",
		                		data:$('#f1').serialize(),// 你的formid
		                		async: false,
				                error: function(requests) {
				                    alert("Connection error");
				                },
				                success:function(datas){
				                	var res1=JSON.parse(datas);
				                	if(res1["state"]==1){
				                		swal({
										title: "完成",
										text: "操作已成功",
										type: "success"
										},function(){
											parent.window.location="{:url('Apapply/addform')}?aid="+$("#aid").val();
											parent.layer.close(parent.layer.getFrameIndex(window.name))
										});
				                	}else{
				                		swal({
										title: "错误",
										text:  res1["msg"],
										type: "warning"
										});
				                	}
				                }
				               })
		                	}else{
		                		swal({
									title: "错误",
									text:  rea["msg"],
									type: "warning"
									});
    
		                	}
		                	

		                }
		           })
	    	}else{
	    		//有申请
	    				$.ajax({
		               			cache: true,
		               			type: "POST",
		                		url:"{:url('addapplydetail')}",
		                		data:$('#f1').serialize(),// 你的formid
		                		async: false,
				                error: function(requests) {
				                    alert("Connection error");
				                },
				                success:function(datas){
				                	var res1=JSON.parse(datas);
				                	if(res1["state"]==1){
				                		swal({
										title: "完成",
										text: "操作已成功",
										type: "success"
										},function(){
											parent.window.location="{:url('Apapply/addform')}?aid="+$("#aid").val();
											parent.layer.close(parent.layer.getFrameIndex(window.name))
										});
				                	}else{
				                		swal({
										title: "错误",
										text:  res1["msg"],
										type: "warning"
										});
				                	}
				                }
				               })
	    	}
    	}else{
    			swal({
					title: "错误",
					text:  res["msg"],
					type: "warning"
					});
    	}
    	
    })
    $('body').on("change",".isshi",function(){
    	if($(this).prop("checked")){
    		$(this).parent().prev().val(1);
    	}
    })
    $('body').on("change",".isfou",function(){
    	if($(this).prop("checked")){
    		$(this).parent().prev().prev().val(0);
    	}
    })
    //未税和税率离开格式和核算
    $('body').on("blur",".shuilv",function(){
    	if(isNaN(parseFloat($(this).val()))){
    		$(this).val("0.00");
    	}else{
    		$(this).val(parseFloat($(this).val()).toFixed(2));
    	}
    	var shuilv=parseFloat($(this).val());
    	var weishui=parseFloat($(this).parent().prev().prev().children().val());
    	var hanshui=weishui+weishui*shuilv/100;
    	$(this).parent().next().children().val(hanshui.toFixed(2));
    	$(this).parent().next().next().children().val(hanshui.toFixed(2));
    })
    $('body').on("blur",".weishui",function(){
    	if(isNaN(parseFloat($(this).val()))){
    		$(this).val("0.00");
    	}else{
    		$(this).val(parseFloat($(this).val()).toFixed(2));
    	}
    	var shuilv=parseFloat($(this).parent().next().next().children().val());
    	var weishui=parseFloat($(this).val());
    	var hanshui=weishui+weishui*shuilv/100;
    	$(this).parent().next().next().next().children().val(hanshui.toFixed(2));
    	$(this).parent().next().next().next().next().children().val(hanshui.toFixed(2));
    })
    //同步费用
    // //关闭多选某一项
    $('body').on('click','.duoxuan .closefei',function () {
    	var id=$(this).closest('.ren').attr("data-id");
    	$("#tb>tr").each(function(){
    		if($(this).attr("fid")==id){
    			$(this).remove();
    		}
    	})
        $(this).closest('.ren').remove()
    })
    $('body').on("click",".closeit",function(){
    	var id=$(this).parent().parent().parent().attr("fid");
    	$("#selected_feiyong3>.ren").each(function(){
    		if($(this).attr("data-id")==id){
    			$(this).remove();
    		}
    	})
    	$(this).parent().parent().parent().remove();
    })
      $('.clear_feiyong').on('click',function () {
            $(this).closest('tr').next('tr').find('.duoxuan').html('');
            $("#tb").html("");
            return false
        })
       //取消单选
    $('body').on('click','.selectedOnlyOne .close',function () {
        $(this).closest('.selectedOnlyOne').hide().find('.inin').html('')
        $(this).closest('.selectedOnlyOne').prev('.input-group').show().find('input').val('')
    })
    	  //供应商搜索自动补全
    $(".gys").bsSuggest({
        url: "{:url('gysjson')}",
        /*effectiveFields: ["userName", "shortAccount"],
         searchFields: [ "shortAccount"],*/
        effectiveFieldsAlias:{title: "名称"},
        ignorecase: true,
        showHeader: true,
        showBtn: false,     //不显示下拉按钮
        delayUntilKeyup: true, //获取数据的方式为 firstByUrl 时，延迟到有输入/获取到焦点时才请求数据
        idField: "id",
        keyField: "title",
        clearable: true
    }).on('onSetSelectValue', function (e, keyword, data) {
        $(this).closest('.input-group').hide().next('.selectedOnlyOne').show().find('.inin').html(keyword.key)
        $(this).val(keyword.id)

    });

      //弹出选择我的供应商树
        $('body').on('click','.select_gys',function () {
            var _this = this
                layer.open({
                    type:2,
                    area:['60%','60%'],
                    title:'费用计入部门树',
                    maxmin:true,
                    content:'{:url("selectGys")}',
                    btn:'确定',
                    btnAlign:'c',
                    yes:function (i,o) {

                        var id = $(o).find('iframe').contents().find('#renyuan').val()
                        var name = $(o).find('iframe').contents().find('#renyuanname').val()
                        if(id){
                            $(_this).closest('div').prev('div').find('.input-group').hide().find('.feetype').val(id)
                            $(_this).closest('div').prev('div').find('.selectedOnlyOne').show().find('.inin').html(name)
                        }
                        layer.close(i)
                    }
                })
                return  false
        })


     //清空网点或产品
        $('.clear_net').on('click',function () {
            $(this).closest('tr').next('tr').find('.duoxuan').html('')
            return false
        })

    //关闭多选某一项
    $('body').on('click','.duoxuan .close',function () {
        $(this).closest('.ren').remove()
    })
      //网点搜索自动补全
    $("#wangdian").bsSuggest({
        url: "{:url('select/mynetjson')}",
        /*effectiveFields: ["userName", "shortAccount"],
         searchFields: [ "shortAccount"],*/
        effectiveFieldsAlias:{title: "名称"},
        ignorecase: true,
        showHeader: true,
        showBtn: false,     //不显示下拉按钮
        delayUntilKeyup: true, //获取数据的方式为 firstByUrl 时，延迟到有输入/获取到焦点时才请求数据
        idField: "id",
        keyField: "title",
        clearable: true
    }).on('onSetSelectValue', function (e, keyword, data) {
        $(this).val('')
        var bool = false
        $('#selected_wangdian .ren').each(function (idx,o) {
            if($(this).data('id') == keyword.id){
                bool = true;
            }
        })
        if(bool == false){
            $('#selected_wangdian').append('<span class="ren" data-id="'+keyword.id+'">'+keyword.key+'<span class="close">×</span></span>')
        }
    });
      //弹出选择网点
        $('#select_wangdian').on('click',function () {
                var index = layer.getFrameIndex(window.name)
                layer.open({
                    type:2,
                    area:['60%','60%'],
                    maxmin:true,
                    content:'{:url("selectWangdian")}'
                })
                return  false
        })
     //系统搜索自动补全
    $("#xt").bsSuggest({
        url: "{:url('select/mysysjson')}",
        /*effectiveFields: ["userName", "shortAccount"],
         searchFields: [ "shortAccount"],*/
        effectiveFieldsAlias:{title: "名称"},
        ignorecase: true,
        showHeader: true,
        showBtn: false,     //不显示下拉按钮
        delayUntilKeyup: true, //获取数据的方式为 firstByUrl 时，延迟到有输入/获取到焦点时才请求数据
        idField: "id",
        keyField: "title",
        clearable: true
    }).on('onSetSelectValue', function (e, keyword, data) {
        $(this).val('')
        var bool = false
        $('#selected_xt .ren').each(function (idx,o) {
            if($(this).data('id') == keyword.id){
                bool = true;
            }
        })
        if(bool == false){
            $('#selected_xt').append('<span class="ren" data-id="'+keyword.id+'">'+keyword.key+'<span class="close">×</span></span>')
        }
    });
     //弹出选择系统
        $('#select_xt').on('click',function () {
                var index = layer.getFrameIndex(window.name)
                layer.open({
                    type:2,
                    area:['60%','60%'],
                    maxmin:true,
                    content:'{:url("selectXt")}'
                })
                return  false
        })
                //经销商搜索自动补全
    $("#jxs").bsSuggest({
        url: "{:url('select/myjxsjson')}",
        /*effectiveFields: ["userName", "shortAccount"],
         searchFields: [ "shortAccount"],*/
        effectiveFieldsAlias:{title: "名称"},
        ignorecase: true,
        showHeader: true,
        showBtn: false,     //不显示下拉按钮
        delayUntilKeyup: true, //获取数据的方式为 firstByUrl 时，延迟到有输入/获取到焦点时才请求数据
        idField: "id",
        keyField: "title",
        clearable: true
    }).on('onSetSelectValue', function (e, keyword, data) {
        $(this).val('')
        var bool = false
        $('#selected_jxs .ren').each(function (idx,o) {
            if($(this).data('id') == keyword.id){
                bool = true;
            }
        })
        if(bool == false){
            $('#selected_jxs').append('<span class="ren" data-id="'+keyword.id+'">'+keyword.key+'<span class="close">×</span></span>')
        }
    });
         //弹出选择经销商
        $('#select_jxs').on('click',function () {
                var index = layer.getFrameIndex(window.name)
                layer.open({
                    type:2,
                    area:['60%','60%'],
                    maxmin:true,
                    content:'{:url("selectJxs")}'
                })
                return  false
        })
              //市搜索自动补全
    $("#shi").bsSuggest({
        url: "{:url('shijson')}",
        /*effectiveFields: ["userName", "shortAccount"],
         searchFields: [ "shortAccount"],*/
        effectiveFieldsAlias:{title: "名称"},
        ignorecase: true,
        showHeader: true,
        showBtn: false,     //不显示下拉按钮
        delayUntilKeyup: true, //获取数据的方式为 firstByUrl 时，延迟到有输入/获取到焦点时才请求数据
        idField: "id",
        keyField: "title",
        clearable: true
    }).on('onSetSelectValue', function (e, keyword, data) {
        $(this).val('')
        var bool = false
        $('#selected_shi .ren').each(function (idx,o) {
            if($(this).data('id') == keyword.id){
                bool = true;
            }
        })
        if(bool == false){
            $('#selected_shi').append('<span class="ren" data-id="'+keyword.id+'">'+keyword.key+'<span class="close">×</span></span>')
        }
    });
        //弹出选择市框
        $('#select_shi').on('click',function () {
                var index = layer.getFrameIndex(window.name)
                layer.open({
                    type:2,
                    area:['60%','60%'],
                    maxmin:true,
                    content:'{:url("selectShi")}'
                })
                return  false
        })
            //省份搜索自动补全
    $("#sheng").bsSuggest({
        url: "{:url('shengjson')}",
        /*effectiveFields: ["userName", "shortAccount"],
         searchFields: [ "shortAccount"],*/
        effectiveFieldsAlias:{title: "名称"},
        ignorecase: true,
        showHeader: true,
        showBtn: false,     //不显示下拉按钮
        delayUntilKeyup: true, //获取数据的方式为 firstByUrl 时，延迟到有输入/获取到焦点时才请求数据
        idField: "id",
        keyField: "title",
        clearable: true
    }).on('onSetSelectValue', function (e, keyword, data) {
        $(this).val('')
        var bool = false
        $('#selected_sheng .ren').each(function (idx,o) {
            if($(this).data('id') == keyword.id){
                bool = true;
            }
        })
        if(bool == false){
            $('#selected_sheng').append('<span class="ren" data-id="'+keyword.id+'">'+keyword.key+'<span class="close">×</span></span>')
        }
    });
     //弹出选择省框
        $('#select_sheng').on('click',function () {
                var index = layer.getFrameIndex(window.name)
                layer.open({
                    type:2,
                    area:['60%','60%'],
                    maxmin:true,
                    content:'{:url("selectSheng")}'
                })
                return  false
        })

           //分区搜索自动补全
    $("#fenqu").bsSuggest({
        url: "{:url('fenqujson')}",
        /*effectiveFields: ["userName", "shortAccount"],
         searchFields: [ "shortAccount"],*/
        effectiveFieldsAlias:{title: "名称"},
        ignorecase: true,
        showHeader: true,
        showBtn: false,     //不显示下拉按钮
        delayUntilKeyup: true, //获取数据的方式为 firstByUrl 时，延迟到有输入/获取到焦点时才请求数据
        idField: "id",
        keyField: "title",
        clearable: true
    }).on('onSetSelectValue', function (e, keyword, data) {
        $(this).val('')
        var bool = false
        $('#selected_fenqu .ren').each(function (idx,o) {
            if($(this).data('id') == keyword.id){
                bool = true;
            }
        })
        if(bool == false){
            $('#selected_fenqu').append('<span class="ren" data-id="'+keyword.id+'">'+keyword.key+'<span class="close">×</span></span>')
        }
    });

  //弹出选择分区框
        $('#select_fenqu').on('click',function () {
                var index = layer.getFrameIndex(window.name)
                layer.open({
                    type:2,
                    area:['60%','60%'],
                    maxmin:true,
                    content:'{:url("selectFenqu")}'
                })
                return  false
        })


         //费用科目三搜索自动补全
   
    $("#feiyong3").bsSuggest({
        url: "{:url('feiyong3json')}?esuseway=6&channel="+channel,
        /*effectiveFields: ["userName", "shortAccount"],
         searchFields: [ "shortAccount"],*/
        effectiveFieldsAlias:{title: "名称"},
        ignorecase: true,
        showHeader: true,
        showBtn: false,     //不显示下拉按钮
        delayUntilKeyup: true, //获取数据的方式为 firstByUrl 时，延迟到有输入/获取到焦点时才请求数据
        idField: "id",
        keyField: "title",
        clearable: true
    }).on('onSetSelectValue', function (e, keyword, data) {
        $(this).val('')
        var bool = false
        $('#selected_feiyong3 .ren').each(function (idx,o) {
            if($(this).data('id') == keyword.id){
                bool = true;
            }
        })
        if(bool == false){
            $('#selected_feiyong3').append('<span class="ren" data-id="'+keyword.id+'">'+keyword.key+'<span class="closefei">×</span></span>');
            $.post("{:url('addfeiyong')}",{id:keyword.id,title:keyword.key},function(re){
            	$("#tb").append(re);
            	 //费用计入部门搜索自动补全
	             $(".gys").bsSuggest({
			        url: "{:url('gysjson')}",
			        /*effectiveFields: ["userName", "shortAccount"],
			         searchFields: [ "shortAccount"],*/
			        effectiveFieldsAlias:{title: "名称"},
			        ignorecase: true,
			        showHeader: true,
			        showBtn: false,     //不显示下拉按钮
			        delayUntilKeyup: true, //获取数据的方式为 firstByUrl 时，延迟到有输入/获取到焦点时才请求数据
			        idField: "id",
			        keyField: "title",
			        clearable: true
			    }).on('onSetSelectValue', function (e, keyword, data) {
			        $(this).closest('.input-group').hide().next('.selectedOnlyOne').show().find('.inin').html(keyword.key)
			        $(this).val(keyword.id)

			    });
            })

        }
    });
     //弹出选择费用框
        $('#select_feiyong3').on('click',function () {
                var index = layer.getFrameIndex(window.name)
                layer.open({
                    type:2,
                    area:['60%','60%'],
                    maxmin:true,
                    content:'{:url("selectFeiyong")}?esuseway=6&channel='+channel+'&index='+index
                })
                return  false
        })

       //产品品牌搜索自动补全
    $("#brand").bsSuggest({
        url: "{:url('select/brandjson')}",
        /*effectiveFields: ["userName", "shortAccount"],
         searchFields: [ "shortAccount"],*/
        effectiveFieldsAlias:{title: "名称"},
        ignorecase: true,
        showHeader: true,
        showBtn: false,     //不显示下拉按钮
        delayUntilKeyup: true, //获取数据的方式为 firstByUrl 时，延迟到有输入/获取到焦点时才请求数据
        idField: "id",
        keyField: "title",
        clearable: true
    }).on('onSetSelectValue', function (e, keyword, data) {
        $(this).val('')
        var bool = false
        $('#selected_brand .ren').each(function (idx,o) {
            if($(this).data('id') == keyword.id){
                bool = true;
            }
        })
        if(bool == false){
            $('#selected_brand').append('<span class="ren" data-id="'+keyword.id+'">'+keyword.key+'<span class="close">×</span></span>')
        }
    });
      //产品品类搜索自动补全
    $("#category").bsSuggest({
        url: "{:url('select/categoryjson')}",
        /*effectiveFields: ["userName", "shortAccount"],
         searchFields: [ "shortAccount"],*/
        effectiveFieldsAlias:{title: "名称"},
        ignorecase: true,
        showHeader: true,
        showBtn: false,     //不显示下拉按钮
        delayUntilKeyup: true, //获取数据的方式为 firstByUrl 时，延迟到有输入/获取到焦点时才请求数据
        idField: "id",
        keyField: "title",
        clearable: true
    }).on('onSetSelectValue', function (e, keyword, data) {
        $(this).val('')
        var bool = false
        $('#selected_category .ren').each(function (idx,o) {
            if($(this).data('id') == keyword.id){
                bool = true;
            }
        })
        if(bool == false){
            $('#selected_category').append('<span class="ren" data-id="'+keyword.id+'">'+keyword.key+'<span class="close">×</span></span>')
        }
    });
    //产品系列搜索自动补全
    $("#series").bsSuggest({
        url: "{:url('select/seriesjson')}",
        /*effectiveFields: ["userName", "shortAccount"],
         searchFields: [ "shortAccount"],*/
        effectiveFieldsAlias:{title: "名称"},
        ignorecase: true,
        showHeader: true,
        showBtn: false,     //不显示下拉按钮
        delayUntilKeyup: true, //获取数据的方式为 firstByUrl 时，延迟到有输入/获取到焦点时才请求数据
        idField: "id",
        keyField: "title",
        clearable: true
    }).on('onSetSelectValue', function (e, keyword, data) {
        $(this).val('')
        var bool = false
        $('#selected_series .ren').each(function (idx,o) {
            if($(this).data('id') == keyword.id){
                bool = true;
            }
        })
        if(bool == false){
            $('#selected_series').append('<span class="ren" data-id="'+keyword.id+'">'+keyword.key+'<span class="close">×</span></span>')
        }
    });
        //弹出选择品牌框
        $('#select_brand').on('click',function () {
                var index = layer.getFrameIndex(window.name)
                layer.open({
                    type:2,
                    area:['60%','60%'],
                    maxmin:true,
                    content:'{:url("selectBrands")}?index='+index
                })
                return  false
        })


             //弹出选择品类框
        $('#select_category').on('click',function () {
                var index = layer.getFrameIndex(window.name)
                layer.open({
                    type:2,
                    area:['60%','60%'],
                    maxmin:true,
                    content:'{:url("selectCategory")}?index='+index
                })
                return  false
        })

        //弹出选择系列框
        $('#select_series').on('click',function () {
                var index = layer.getFrameIndex(window.name)
                layer.open({
                    type:2,
                    area:['60%','60%'],
                    maxmin:true,
                    content:'{:url("selectSeries")}?index='+index
                })
                return  false
        })
    //日期范围限制
        var start = {
            elem: '#start',
            format: 'YYYY-MM-DD',
          
            max: '2099-06-16 23:59:59', //最大日期
            istime: true,
            istoday: false,
            choose: function (datas) {
                end.min = datas; //开始日选好后，重置结束日的最小日期
                end.start = datas //将结束日的初始值设定为开始日

            }
        };
        var end = {
            elem: '#end',
            format: 'YYYY-MM-DD',
            min: laydate.now(),
            max: '2099-06-16 23:59:59',
            istime: true,
            istoday: false,
            choose: function (datas) {
                start.max = datas; //结束日选好后，重置开始日的最大日期
                yjverifyTime.min=datas;
                  $.post("{:url('TiApply/gettwomon')}",{datet:datas},function(re){
                	//alert(re);
                	$("#yjverifyTime").val(re);
                })	
            }
        };
      	var yjverifyTime={
 			elem: '#yjverifyTime',
            format: 'YYYY-MM-DD',
            min: laydate.now(), //设定最小日期为当前日期
            max: '2099-06-16 23:59:59', //最大日期
            istime: true,
            istoday: false,

      	}
      	laydate(yjverifyTime);
        laydate(start);
        laydate(end);
       
    </script>
</body>

</html>
